/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: col</p>
 */
package com.googlecode.cswish.security.type;

import java.util.ArrayList;
import java.util.Collection;

/**
 * field permission control
 *
 * a structure that describles user can operate how many fields in current operation
 *
 * @author Jerry.Feng Date: 2005-7-4 15:35:00
 * @version $id: $
 */
public class Method {
	public static final String ALL = "*";
	
	String formAction;

	Collection fields;
	
	public Method(String formAction) {
		this.formAction = formAction;
	}

	public String getFormAction() {
		return formAction;
	}

	public void setFormAction(String formAction) {
		this.formAction = formAction;
	}

	public Collection getFields() {
		return fields;
	}

	public void setFields(Collection fields) {
		this.fields = fields;
	}

	public void addField(Field field) {
		if (fields == null) {
			fields = new ArrayList();
		}
		if (!fields.contains(field)) {
			fields.add(field);
		}
	}

	public boolean equals(Object anObject) {
		if (this == anObject) {
			return true;
		}
		if (formAction == null) {
			return false;
		}

		if (anObject instanceof Method) {
			Method another = (Method)anObject;

			return formAction.equals(another.getFormAction());
		} else {
			return false;
		}
	}
}
